package com.awangyh.jdk8.thread;

import java.util.concurrent.*;

/**
 * Created by admin on 2017/4/8.
 */
public class CompletableDemo {

	public static void main(String[] args) throws Exception {
		ExecutorService executor = Executors.newFixedThreadPool(5);
		CompletableFuture<String> resultFuture = CompletableFuture.supplyAsync(() -> {
			System.out.println("completableFuture 1 running");

			try {
				TimeUnit.SECONDS.sleep(2);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

			System.out.println("completableFuture 1 completed.");
			return "hello completablefuture";
		}, executor);

		System.out.println(" main thread complete");
		//调用Future的get()方法获取执行结果。
		//System.out.println(resultFuture.get());

        resultFuture.thenAcceptAsync((m) -> {
            System.out.println(m);
            System.out.println("Get Result by Back Function ");
        });

        executor.shutdown();
	}
}
